﻿using System;

namespace AI_Experiment
{
    class Droid
    {
        public int id;              //id number for the droid
        public int moveTally;       //tally of total moves used
        public int foodEaten;       //total amount of food eaten
        public int nearestFood;     //nearest food to droid
        public int cur_x, cur_y;    //current coordinates, x and y, assigned at spawn
        public int next_x, next_y;  //planned next move coordinates, used in "move" method
        public bool isDead; //bool for fights over food or each other

        public Droid(int idNum)
        {
            id = idNum;
            moveTally = 0;
            foodEaten = 0;
            cur_x = GlobalVars.random.Next(0, GlobalVars.boardSize_x);
            cur_y = GlobalVars.random.Next(0, GlobalVars.boardSize_y);
        }

        public void setNextMove(Food food)
        {
            int nextFood_x = food.cur_x;
            int nextFood_y = food.cur_y;

            Console.WriteLine("Got this far!");

            //perform checks here, above/below then left/right

            //if food object is above droid
            if (nextFood_y < cur_y)
            {
                //if food object is to the left
                if (nextFood_x < cur_x)
                {
                    next_x = cur_x--;
                    Console.WriteLine( cur_x);
                } //if the food is to the right
                else if (nextFood_x > cur_x)
                {
                    next_x = cur_x++;
                    Console.WriteLine(cur_x);
                    Console.WriteLine(cur_y);
                }
            }//if food objext is below
            else if (nextFood_y > cur_y){
                //if food object is to the left
                if (nextFood_x > cur_x)
                {
                    next_x--;
                    Console.WriteLine(cur_x);
                    Console.WriteLine(cur_y);
                } //if the food is to the right
                else if (nextFood_x > cur_x)
                {
                    next_x++;
                    Console.WriteLine(cur_x);
                    Console.WriteLine(cur_y);
                }
            }//if food object is on the same y, but to the left
            else if ((nextFood_y == cur_y) && (nextFood_x < cur_x))
            {
                next_x = cur_x--;
                Console.WriteLine(cur_x);
                Console.WriteLine(cur_y);
            }//if food object is on the same y, but to the right
            else if ((nextFood_y == cur_y) && (nextFood_x > cur_x))
            {
                next_x = cur_x++; 
                Console.WriteLine(cur_x);
                Console.WriteLine(cur_y);
            }//if we're on the food object..
            else if ((nextFood_y == cur_y) && (nextFood_x == cur_x))
            {
                food.isEaten = true; //the food is eaten.
                foodEaten++;
                GlobalVars.totalFoods--;
                Console.WriteLine("Total food left: " + GlobalVars.totalFoods);
                Console.WriteLine(cur_x);
                Console.WriteLine(cur_y);
            }
        }
    }
}